import { apiGetRoleOptions } from '@/api/sys/role';
import { BasicColumn, FormSchema } from '@/components/Table';
// import { h } from 'vue';
// import { Image } from 'ant-design-vue';
import { Sex, SexOptions, Status, StatusOptions, StatusTag } from '@/enums/fieldsEnum';

export const columns: BasicColumn[] = [
  {
    title: '用户名',
    dataIndex: 'username',
    width: 120,
    sorter: true,
  },
  {
    title: '昵称',
    dataIndex: 'nick_name',
    width: 120,
    sorter: true,
  },
  // {
  //   title: '头像',
  //   dataIndex: 'avatar',
  //   width: 120,
  //   customRender: ({ record }) => {
  //     return h(Image, { src: record.avatar });
  //   },
  // },
  {
    title: '邮箱',
    dataIndex: 'email',
    width: 120,
  },
  {
    title: '手机',
    dataIndex: 'phone',
    width: 120,
    sorter: true,
  },
  {
    title: '状态',
    dataIndex: 'status',
    customRender: ({ record }) => StatusTag(record.status),
  },
  {
    title: '创建时间',
    dataIndex: 'created_at',
    width: 180,
    sorter: true,
  },
  {
    title: '角色',
    dataIndex: 'role_id',
    width: 200,
    customRender: ({ record }) => {
      return record?.role?.role_name;
    },
  },
  {
    title: '部门',
    dataIndex: 'dept_id',
    width: 200,
    customRender: ({ record }) => {
      return record?.dept?.dept_name;
    },
  },
  {
    title: '备注',
    dataIndex: 'remark',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'username',
    label: '用户名或昵称',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: StatusOptions,
    },
  },
];

export const accountFormSchema: FormSchema[] = [
  {
    field: 'username',
    label: '用户名',
    component: 'Input',
    helpMessage: ['登陆用户名'],
    required: true,
  },
  {
    field: 'password',
    label: '密码',
    component: 'InputPassword',
    helpMessage: ['登陆密码'],
    required: true,
  },
  {
    field: 'nick_name',
    label: '昵称',
    component: 'Input',
    required: true,
  },
  {
    label: '手机',
    field: 'phone',
    component: 'Input',
  },
  {
    field: 'sex',
    label: '性别',
    component: 'RadioGroup',
    defaultValue: Sex.Male,
    componentProps: {
      options: SexOptions,
    },
    required: true,
  },
  {
    label: '角色',
    field: 'role_id',
    component: 'ApiSelect',
    defaultValue: 1,
    componentProps: {
      api: apiGetRoleOptions,
      resultField: 'options',
      labelField: 'text',
      valueField: 'value',
    },
    required: true,
  },
  // {
  //   label: '头像',
  //   field: 'avatar_arr',
  //   component: 'Upload',
  //   defaultValue: [],
  //   colProps: {
  //     span: 8,
  //   },
  //   componentProps: {
  //     api: uploadApi,
  //     multiple: false,
  //     uploadParams: {
  //       type: UploadType.Avatar,
  //     },
  //   },
  // },
  {
    field: 'dept_id',
    label: '所属部门',
    component: 'TreeSelect',
    componentProps: {
      fieldNames: {
        label: 'dept_name',
        value: 'dept_id',
      },
      getPopupContainer: () => document.body,
    },
    required: true,
  },

  {
    label: '邮箱',
    field: 'email',
    component: 'Input',
  },

  // {
  //   label: '头像',
  //   field: 'avatar',
  //   component: 'Input',
  // },

  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: Status.Enabled,
    componentProps: {
      options: StatusOptions,
    },
    required: true,
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },
];
